using SDL;
using Gee;

class KeySynthesizer : Object {

	public int buffer_size { get; private set; }
	public Window window { get; set; }
	public BoundedList<Key?> key_events { get; private set; }
	public ArrayList<ArrayList<Key?>> sequences = new ArrayList<ArrayList<Key?>>();
	public signal void on_key_sequence(ArrayList<Key?> keys);
	
	public void register_sequence(ArrayList<Key?> keys)
		requires (keys.size < this.buffer_size) {
		this.sequences.add(keys);

	}

	public void remove_sequence(ArrayList<Key?> keys) {
		this.sequences.remove(keys);
	}

	private void handle_key_down(Object sender, KeyboardEvent event) {
		stderr.printf("Key down: %s\n", Key.get_name(event.keysym.sym));
	}

	private void handle_key_up(Object sender, KeyboardEvent event) {
		stderr.printf("Key up: %s\n", Key.get_name(event.keysym.sym));
		this.key_events.add(event.keysym);
		this.match_sequence();
	}

	private void match_sequence() {
		foreach (ArrayList<Key?> sequence in this.sequences) {

		}
	}

	public KeySynthesizer(int size, Window window) {
		this.buffer_size = size;
		this.key_events = new BoundedList<Key?>(this.buffer_size);
		this.window = window;
		this.window.on_key_down.connect(this.handle_key_down);
		this.window.on_key_up.connect(this.handle_key_up);
	}

}



